@extends('layouts.app')
@section('title', config('seo_title').'-'.translate('注册'))
@section('footer')
     @include('common.footer')
@stop
@section('content')
<div class="container" id="container">
        <div class="wrapper">
            <div id="minHeight" class="minHeight">
               	@include('common.header', ['title'=>translate('注册')])
                <div class="main_body">
                    <div class="reg">
                    <form id="form1" method="POST" action="{{ route('register') }}">
     {{ csrf_field() }}
                        <div id="login" name="login">

                            <div class="control-group">
                                <input type="text" name="mobile" id="phone" class="input-style1" placeholder="{{translate('请输入手机号码')}}">
                            </div>
                            <div class="control-group">
                                <input type="password" name=password id="pwd" class="input-style1" placeholder="{{translate('请输入密码')}}">
                            </div>
                            <div class="control-group">
                                <input type="password" name="repassword" id="repwd" class="input-style1" placeholder="{{translate('密码确认')}}">
                            </div>
                            <div class="control-group msg">
                                <input type="text" id="msgcode" class="msgcode" name="code" maxlength="6" placeholder="{{translate('输入您收到的短信验证码')}}">
                                <a href="javascript:SendPhone();" id="sendCode" style="background-color: #999" class="sendcode">{{translate('获取验证码')}}</a>
                            </div>
                            <div class="control-group">

                                <input type="submit" id="submit" class="btn-style1" value="{{translate('立即注册')}}">
                            </div>
                        </div>
                        <!--<div class="clearfix">
                            <label class="default-cursor">
                                <input type="checkbox" class="fl" name="rules" id="rules" value="1" checked />
                                <span class="fl">我已阅读并接受《<a href="/User/Agreement" class="rules">注册协议</a>》</span>
                            </label>
                        </div>-->
                    </div>
                </div>

                <script type="text/javascript">
                    // $("#phone").blur(function () {
                    //     phone = this.value;
                    //     RegCellPhone = /^(1)([0-9]{10})?$/;
                    //     falg=phone.search(RegCellPhone);
                    //     if (falg==-1){
                    //         $.prompt("{{translate('请输入手机号码')}}");
                    //
                    //         return false;
                    //         this.focus();
                    //     }
                    // });
                    //验证手机号码
                    function checkTel(phone) {
                        var reg = /^1[3|4|5|7|8](\d){9}$/;
                        if (reg.test(phone)) {
                            return true;
                        } else {
                            return false;
                        }
                    }
                    //手机号码焦点离开事件
                    // function is_reg_phone() {
                    //     debugger;
                    //     var phone = $("#phone").val();
                    //     if (phone.length != 11) {
                    //         $.prompt("请输入您的11位手机号码", {
                    //             buttons: { "确定": true }
                    //         });
                    //         return;
                    //     }else if (phone.length == 11) {
                    //         if (!checkTel(phone)) {
                    //             $.prompt("您的手机号码不正确", {
                    //                 buttons: { "确定": true }
                    //             });
                    //             return;
                    //         } else {//验证手机号码是否可以注册
                    //             $.ajax({
                    //                 url: "../login/checkPhone",
                    //                 type: 'post',
                    //                 dataType: 'json',
                    //                 data: { phone: phone },
                    //                 success: function (data) {
                    //                     debugger;
                    //                     if (data.status == 1) {
                    //                         $("#sendCode_register").css({ "background": "#999" });
                    //                         $.prompt(data.msg, {
                    //                             buttons: { "确定": true }
                    //                         });
                    //                     } else {
                    //                         $("#sendCode_register").css({ "background": "#093" });
                    //                     }
                    //                 },
                    //                 error: function () {
                    //                     alert('服务器繁忙..请稍后重试！');
                    //                 }
                    //             });
                    //         }
                    //     }
                    // }

                    //验证登陆密码
                    function is_reg_pwd()
                    {
                        var pwd = $.trim($("#pwd").val());//密码
                        if (pwd.length < 6 || pwd.length > 16) {
                            $.prompt("{{translate('密码长度为6-16位')}}", {
                                buttons: { "{{translate('确定')}}": true }
                            });
                            return;
                        }
                    }

                    //验证确认密码
                    function checkPwd(pwd, repwd) {
                        if (pwd == repwd) {
                            return true;
                        } else {
                            return false;
                        }
                    }


                    var sendVerifyNum = 0;
                    //发送手机证码
                    function SendPhone() {
                        var phone = $.trim($("#phone").val());//获取手机号码
                        if (sendVerifyNum == 0) {
                        	ajaxurl('/sendsms',{mobile:phone}, ajaxMsgPhone)

                        } else {
                            //Showbo.Msg.alert("验证码已发到您手机，请查收！", "消息提示");
                            $.prompt("{{translate('验证码已发到您手机，请查收')}}！", {
                                buttons: { "{{translate('确定')}}": true }
                            });
                        }
                    }
                    //手机验证码发送成功返回函数
                    function ajaxMsgPhone(jsonData) {
                        if (jsonData.Statu == 0) {//成功
                            $("#sendCode").disabled = "disabled";
                            sendVerifyNum = 60;
                            var that = this;
                            //计时器
                            that.timer = setInterval(function () {
                                sendVerifyNum--;
                                $("#sendCode").html("" + sendVerifyNum + " 秒");
                                if (sendVerifyNum <= 1) {
                                    sendVerifyNum = 0;
                                    $("#sendCode").html("{{translate('获取验证码')}}");
                                    $("#sendCode").disabled = "";
                                    clearInterval(that.timer);
                                }
                            }, 1000);

                            $.prompt(jsonData.Msg, {
                                buttons: { "{{translate('确定')}}": true }
                            });

                        } else {
                            $.prompt(jsonData.Msg, {
                                buttons: { "{{translate('确定')}}": true }
                            });
                        }
                    }
                    //是否同意注册协议
                    $("#rules").click(function () {
                        var _self = $(this);
                        if (_self.prop("checked")) {
                            $(".btn-style1").css("background", "");
                            $(".btn-style1").addClass('submit');
                            _self.val(1);
                        } else {
                            $(".btn-style1").css("background", "grey");
                            $(".btn-style1").removeClass('submit');
                            _self.val(0);
                        }
                    });

                    //注册
                    $("body").delegate('#submit', 'click', function () {
                        var that = $(this);
                        that.attr('id', '');
                        that.text('处理中');
                        that.css('background', '#808080');
                        //var name = $.trim($("#name").val());
                        var pwd = $.trim($("#pwd").val());
                        var repwd = $.trim($("#repwd").val());
                        var phone = $.trim($("#phone").val());
                        var msgcode = $.trim($("#msgcode").val());
                        var rules = $("#rules").val();
                        //if (checkTel(phone) && pwd != '' && checkPwd(pwd, repwd) && rules == '1' && msgcode != '') {
                        if (checkTel(phone) && pwd != '' && checkPwd(pwd, repwd)  && msgcode != '') {
                            if (pwd.length < 6 || pwd.length > 16) {
                                $.prompt("{{translate('密码长度为6-16位')}}", {
                                    buttons: { "{{translate('确定')}}": true }
                                });
                                that.attr('id', 'submit');
                                that.text("{{translate('立即注册')}}");
                                that.css('background', '#093');
                            }
                            else {
                                $('#form1').submit();
                            }
                        } else {
                            if (pwd == '' || repwd == '' || msgcode == '' || phone == '') {
                                $.prompt("{{translate('请将信息填写完整')}}", {
                                    buttons: { "{{translate('确定')}}": true }
                                });
                            } else if (!checkPwd(pwd, repwd)) {
                                $.prompt("{{translate('密码不一致')}}", {
                                    buttons: { "{{translate('确定')}}": true }
                                });
                            } else if (!checkTel(phone)) {
                                $.prompt("{{translate('请输入正确的手机号码')}}", {
                                    buttons: { "{{translate('确定')}}": true }
                                });
                            }
                            // else if (rules == '0') {
                            //     $.prompt("请同意协议", {
                            //         buttons: { "确定": true }
                            //     });
                            // }
                            else {

                            }
                            that.attr('id', 'submit');
                            that.text("{{translate('立即注册')}}");
                            that.css('background', '#093');

                        }
                    });


                    $(window).on('load', function () {
                        setTimeout(function () { window.scrollTo(0, 1); }, 100);
                    })
                </script>
            </div>
        </div>
    </div>


@endsection
